/**
 * 
 */
package kr.co.insoft.auth.model.security;

import kr.co.insoft.framework.config.RoleTypes;

import org.springframework.security.core.GrantedAuthority;

/**
 * @author IN-SOFT Inc. GoodwillDD(sylee@in-soft.co.kr)
 * 
 */
public class Role implements GrantedAuthority {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1254968058115699096L;
	static final String ROLE_CUSER = RoleTypes.ROLE_CUSER.name();
	static final String ROLE_NUSER = RoleTypes.ROLE_NUSER.name();
	static final String ROLE_ADMIN = RoleTypes.ROLE_ADMIN.name();
	static final String ROLE_SUPERADMIN = RoleTypes.ROLE_SUPERADMIN.name();
	String role;

	public Role() {
	}

	public Role(final String role) {
		this.role = role;
	}

	public static Role createCompanyUserRole() {
		return new Role(ROLE_CUSER);
	}
	
	public static Role createNormalUserRole() {
		return new Role(ROLE_NUSER);
	}

	public static Role createAdminRole() {
		return new Role(ROLE_ADMIN);
	}

	public static Role createSuperAdminRole() {
		return new Role(ROLE_SUPERADMIN);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.security.core.GrantedAuthority#getAuthority()
	 */
	public String getAuthority() {
		return getRole();
	}

	@Override
	public int hashCode() {
		return (this.getRole() != null ? this.getRole().hashCode() : 0);
	}

	@Override
	public boolean equals(final Object o) {

		if (this == o) {
			return true;
		}
		if (!(o instanceof Role)) {
			return false;
		}

		final Role role = (Role) o;

		return !(this.getRole() != null ? !this.getRole()
				.equals(role.getRole()) : role.getRole() != null);
	}

	/**
	 * @return the role
	 */
	public String getRole() {
		return role;
	}

	/**
	 * @param role
	 *            the role to set
	 */
	public void setRole(String role) {
		this.role = role;
	}

}
